package com.hzjq.encrypt.pop

import android.content.Context
import com.hzjq.encrypt.R
import com.hzjq.encrypt.util.KeyBoradX
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.core.CenterPopupView
import kotlinx.android.synthetic.main.pop_time_layout.view.*

class SqrqPop : CenterPopupView {

    private lateinit var data: String
    private lateinit var c: OnSqrqEditorCallback

    constructor(context: Context) : super(context)

    override fun getImplLayoutId(): Int {
        return R.layout.pop_time_layout
    }

    override fun onCreate() {
        sqrqText.setText(data)
        sqrqDeleteText.setOnClickListener {
            hideKeyBord()
            dismiss()
        }

        sqrqEditorText.setOnClickListener {
            hideKeyBord()
            dismiss()
            data = sqrqText.text.toString()
            c.onSqrqEditor(data)
        }
    }

    private fun hideKeyBord(){
        KeyBoradX.hideKeyBoard(sqrqText)
    }

    interface OnSqrqEditorCallback{
        fun onSqrqEditor(time:String)
    }

    companion object {
        fun show(context: Context, c: OnSqrqEditorCallback, data: String?){
            val pop = SqrqPop(context)
            if(data != null) {
                pop.data = data
            } else {
                pop.data = ""
            }
            pop.c = c
            XPopup.Builder(context)
                .asCustom(pop)
                .show()
        }
    }

}